package com.zzu.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zzu.R;
import com.zzu.model.bean.PackageRouteDetail;

import java.util.List;

/**
 * @ClassName RouteAdapter
 * @Description TODO
 * @Author ZB
 * @Date 2021/5/23 0:45
 * @Version 1.0
 **/
public class RouteAdapter extends RecyclerView.Adapter<RouteAdapter.ViewHolder> {

    private static final String TAG = ThreeAdapter.class.getName();
    private Context mContext;
    private List<PackageRouteDetail> datas;

    public RouteAdapter(Context context, List<PackageRouteDetail> datas) {
        mContext = context;
        this.datas = datas;
        Log.i(TAG,"初始化的数据为"+datas);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_route, null);
        return new RouteAdapter.ViewHolder(view);
    }

    //进行数据的绑定
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //1.根据位置得到对应的Bean对象
        PackageRouteDetail packageRouteDetail = datas.get(position);
        Log.i(TAG,"数据绑定"+packageRouteDetail);
        //2.设置数据
        holder.status.setText(packageRouteDetail.getStringStatue());
        holder.time.setText(packageRouteDetail.getTime());
        holder.position.setText(packageRouteDetail.getTransNode());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView status;
        TextView time;
        TextView position;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            status = itemView.findViewById(R.id.route_status);
            time = itemView.findViewById(R.id.route_time);
            position = itemView.findViewById(R.id.route_position);
        }
    }


}
